package com.kx.smsplantform.strategy.impl;

import com.kx.smsplantform.client.CacheClient;
import com.kx.smsplantform.strategy.Strategy;
import com.kx.smsplantform.utils.PushMessage2Queue;
import com.kx.smsplatform.common.constants.CacheConstants;
import com.kx.smsplatform.common.constants.StrategyConstants;
import com.kx.smsplatform.common.model.StandardSubmit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 黑名单处理策略
 *
 * @Author Sun
 * @Date 2021/7/2 11:36
 */
@Slf4j
@Service(value = "black")
public class BlackStrategy implements Strategy {
    @Autowired
    private CacheClient client;

    @Autowired
    private PushMessage2Queue pushMessage2Queue;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("【策略模块-黑名单校验】 黑名单校验策略开始执行！！");
        //1.获取目标手机号
        String destMobile = standardSubmit.getDestMobile();
        if (!StringUtils.isEmpty(destMobile)) {
            String value = client.get(CacheConstants.CACHE_PREFIX_BLACK + destMobile);
            if ("1".equals(value)) {
                log.info("【策略模块：黑名单策略】黑名单校验未通过！[当前手机号：{}] 为黑名单", destMobile);
                pushMessage2Queue.sendLogMessage(standardSubmit, StrategyConstants.STRATEGY_ERROR_BLACK);
                pushMessage2Queue.pushReportMessage(standardSubmit, StrategyConstants.STRATEGY_ERROR_BLACK);
                return false;
            }
        }
        log.info("【策略模块-黑名单校验】 黑名单校验成功！！");
        return true;
    }
}
